package core.proto;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import org.apache.commons.io.FilenameUtils;

import core.util.logging.UserLogWriter;
import core.util.logging.constants.Action;
import core.util.logging.constants.Location;

public class HighlightToggle extends JButton {
	private static ImageIcon hilightIcon; 
	private boolean isHighlighting;
	private String docName;
	
	static{
		hilightIcon = new ImageIcon(Util.getResourceUrl("/img/highlighter.png"));
	}
	
	
	
	private static String getStatusMsg(boolean isHighlighting){
		return "Highlighting is " + (isHighlighting? "ON" : "OFF");
	}
	
	public boolean isHighlighting(){
		return isHighlighting;
	}
	
	public static HighlightToggle getInstance(final String docName){
		final HighlightToggle instance = new HighlightToggle(docName);
		
		instance.setText(getStatusMsg(instance.isHighlighting));
		instance.setIcon(hilightIcon);
		instance.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent me){
				instance.isHighlighting = ! instance.isHighlighting;
				String status = getStatusMsg(instance.isHighlighting); 
				UserLogWriter.log2(status + " for " + docName, Location.Documents, Action.CLICK);
				instance.setText(status);
			}
		});
		
		return instance; 
	}
	
	private HighlightToggle(String docName){
		super();
		this.docName = docName;
	}
}
